﻿//1、==导入数据到Excel==//
var mExportDataUrl = "";
var mExportDataJson = "";

function setExportExcel(gridname) {  
    var mygrid = mini.get(gridname);
    if (mExportDataUrl == "") mExportDataUrl = mygrid.url;
    var columns = mygrid.getBottomColumns();
    function getColumns(columns) {
        columns[0] = { header: "交班单号", field: "FClassNo" };
        columns[1] = { header: "当班时间", field: "FBeginTime" };
        columns[2] = { header: "交班时间", field: "FEndTime" };
        columns[3] = { header: "单位", field: "FPayAmount0" };
        columns[4] = { header: "数量", field: "mFQty" };
        columns[5] = { header: "单价", field: "mFPrice" };
        columns[6] = { header: "金额", field: "mFAmount" };
        return columns;
    }
    var mSystemAppID = parent.window.getSystemAppID();
    var columns = getColumns(columns);
    //alert(mExportDataUrl);
    $.ajax({
        url: mExportDataUrl,
        data: { mydata: mExportDataJson, pageSize: 0 },
        type: "post",
        dataType: 'text',
        contentType: "application/x-www-form-urlencoded; charset=utf-8",
        success: function (text) {
            var json = "";
            DownLoad("../Data/export.aspx", { type: "excel", columns: columns, griddata: json, FSystemAppID: mSystemAppID });
        },
        ondestroy: function (action) {
            //grid.reload();
        }
    });
}

//1、==导入数据到Excel==//
function ExportExcel(json) {
    var columns = grid.getBottomColumns();
    function getColumns(columns) {
        columns = columns.clone();
        for (var i = columns.length - 1; i >= 0; i--) {
            var column = columns[i];
            if (!column.field) {
                columns.removeAt(i);
            } else {
                var c = { header: column.header, field: column.field };
                columns[i] = c;
            }
        }
        return columns;
    }
    var columns = getColumns(columns);
    //var json = mini.encode(grid.getData());
    DownLoad("../Data/export.aspx", { type: "excel", columns: columns, griddata: json });
}

//2、==导入数据到Excel==//
function DownLoad(url, fields) {
    //创建Form
    var submitfrm = document.createElement("form");
    submitfrm.action = url;
    submitfrm.method = "post";
    submitfrm.target = "_blank";
    document.body.appendChild(submitfrm);

    if (fields) {
        for (var p in fields) {
            var v = fields[p];
            if (v instanceof Array && v.length>13 && v[13].header.indexOf('<') >= 0) {
                v.splice(13, 1);
            }
            var input = mini.append(submitfrm, "<input type='hidden' name='" + p + "'>");
            if (typeof v != "string") v = mini.encode(v);
            input.value = v;
        }
    }
    submitfrm.submit();
    setTimeout(function () {
        submitfrm.parentNode.removeChild(submitfrm);
    }, 1000);
}

function customReportPrin(freport) {
    var myurl = mExportDataUrl + '&pageSize=0';//不按分页导出
    $.ajax({
        url: myurl,
        success: function (text) {
            SetReportPrin(freport);
        },
        ondestroy: function (action) {

        }
    });
}

function SetReportPrin(freport) {
    var mUserID = parent.window.getMyUserID();
    var sql = "exec pr_Rpt_GetReportPrinData " + mUserID;
    mini.open({
        url: "../Common/PrintReport.aspx?Report=" + freport + "&Data=ReportDataService.aspx?BillSQL=" + sql,
        showMaxButton: true,
        title: "打印", width: 810, height: 520,
        onload: function () {
        },
        ondestroy: function (action) {
        }
    });
}
